Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support .lefthook.yml and .lefthook-local.yml #520

Merged
merged 6 commits into from
Jul 17, 2023
Merged

Support .lefthook.yml and .lefthook-local.yml #520

merged 6 commits into from
Jul 17, 2023

Conversation

hyperupcall
Copy link
Contributor

@hyperupcall hyperupcall commented Jul 14, 2023

Closes #319

⚡ Summary

This supports the new .lefthook* formats:

  • As noted in the issue, the dot-prefixed and non-dot-prefixed files do not have any overriding behaviors. The "global" and local files are also resolved separately.
  • The default was also changed to automatically generate a .lefthook.yml if one doesn't already exist.
  • Local config uses -local (.local was suggested, but this is easier and in line with the scripts directory)
  • If both the dot-prefixed and non-dot-prefixed files exist for either "global" or local, no errors are thrown (this was suggested, I did not implement it).

I was wondering some other things:

  • In the uninstall command, I modified things to remove these new config files. Since lefthook supports JSON and TOML files, shouldn't this remove those files as well?

☑️ Checklist

  • Check locally
  • Add tests

@hyperupcall
Copy link
Contributor Author

codecov seemed to decrease but new missed lines seem to be similar to existing ones?

internal/config/load.go Outdated Show resolved Hide resolved
internal/config/load.go Outdated Show resolved Hide resolved
file := filepath.Join(path, config.DefaultConfigName)
file := filepath.Join(path, config.DefaultDotConfigName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep this behavior unchanged? We'll change this in later major release. I think it would be great to just support .lefthook.yml and .lefthook-local.yml by now, fix possible issue, decide on what to do when both variants exist and so on. So, this transition will be smooth. WDYT?

Copy link
Contributor Author

@hyperupcall hyperupcall Jul 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good! The docs don't mention of the dot-prefixed variants so keeping the behavior unchanged means there is no chance of confusion if one is generated or has priority over the non-dot-prefixed variants.

@mrexox
Copy link
Member

mrexox commented Jul 14, 2023

Thank you for the PR! 🎉 I like the code. I've left a few comments about the default behavior.


The default was also changed to automatically generate a .lefthook.yml if one doesn't already exist.

Let's keep this behavior unchanged? Then we can release this PR with just a minor/patch version and polish it before making .lefthook.yml the default.

In the uninstall command, I modified things to remove these new config files. Since lefthook supports JSON and TOML files, shouldn't this remove those files as well?

You are right! I will fix it myself, you don't have to fix this in this PR, thank you for noticing!

@@ -614,12 +614,16 @@ pre-push:
}

t.Run(fmt.Sprintf("%d: %s", i, tt.name), func(t *testing.T) {
if err := fs.WriteFile(filepath.Join(root, "lefthook.yml"), []byte(tt.global), 0o644); err != nil {
t.Errorf("unexpected error: %s", err)
if tt.global != "" {
Copy link
Contributor Author

@hyperupcall hyperupcall Jul 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only write to the config file if we explicitly specify its content. That way, if .lefthook.yml is written to, an empty lefthook.yml doesn't always take precedence

@mrexox mrexox merged commit 27426fa into evilmartians:master Jul 17, 2023
10 checks passed
@hyperupcall hyperupcall deleted the h-dot-lefthook-config branch July 17, 2023 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support new config file format
2 participants